#include <openvino/openvino.hpp>
#include <opencv2/opencv.hpp>

using namespace ov;

// 图像预处理流水线
Tensor preprocess_image(cv::Mat& frame, const Size& model_shape) {
    // 调整尺寸保持纵横比
    float ratio = std::min(model_shape.width / (float)frame.cols,
                          model_shape.height / (float)frame.rows);
    cv::Size new_size(frame.cols * ratio, frame.rows * ratio);
    cv::resize(frame, frame, new_size);

    // 填充到模型输入尺寸
    int dw = model_shape.width - new_size.width;
    int dh = model_shape.height - new_size.height;
    cv::copyMakeBorder(frame, frame, 0, dh, 0, dw, 
                      cv::BORDER_CONSTANT, cv::Scalar(114, 114, 114));

    // 归一化处理 (0-1范围)
    frame.convertTo(frame, CV_32F, 1.0 / 255);

    // 转换为NCHW格式
    cv::Mat blob;
    cv::dnn::blobFromImage(frame, blob, 1.0, cv::Size(), false, false);

    // 创建OpenVINO Tensor对象
    return Tensor(ov::element::f32, 
                 Shape{1, 3, model_shape.height, model_shape.width},
                 blob.data);
}

// 后处理参数结构体
struct PostProcessParam {
    float conf_threshold = 0.5;
    float iou_threshold = 0.45;
    int max_detections = 100;
};